package com.tdrc.common.util;

import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.tdrc.common.beans.ResultCode;

public class JsonResult {
	private int code;
	private String message;
	private Object result;

	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	private long total;
	public JsonResult() {
		this.setCode(ResultCode.OK);
		this.setMessage("成功！");
	}

	public JsonResult(ResultCode code) {
		this.setCode(code);
		this.setMessage(code.msg());
	}
	public JsonResult(ResultCode code, String message, Object result) {
		this.setCode(code);
		this.setMessage(message);
		this.setResult(result);
	}

	public JsonResult(ResultCode code, Object result) {
		this.setCode(code);
		this.setMessage(code.getMsg());
		this.setResult(result);
	}
	public JsonResult(ResultCode code, Object result,long total) {
		this.setCode(code);
		this.setMessage(code.getMsg());
		this.setResult(result);
		this.setTotal(total);
	}
	public String toString() {
		JSONObject json = new JSONObject();
		try {
			json.put("code", code);
			json.put("message", message);
			json.put("result", result);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return json.toString();
	}

	public int  getCode() {
		return code;
	}

	public void setCode(ResultCode code) {
		this.code = code.val();
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public Object getResult() {
		return result;
	}

	public void setResult(Object result) {
		this.result = result;
	}
}